import 'package:appflutterhomeschool/common/common.dart';
import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/route/application.dart';
import 'package:appflutterhomeschool/route/routes.dart';
import 'package:appflutterhomeschool/ui/widgets/button_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/notice/notice_tab_widget.dart';
import 'package:appflutterhomeschool/view_model/my/coure_details_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

///用户： ninetailedfox
///时间： 2020/7/2
///邮箱： 1037438704@qq.com
///功能： 资源库 -> item -> 课程详情页面
class CoureDetailsPage extends StatefulWidget {
  @override
  _CoureDetailsPageState createState() => _CoureDetailsPageState();
}

class _CoureDetailsPageState extends State<CoureDetailsPage>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ProviderWidget<CoureDetailsViewModel>(
      model: CoureDetailsViewModel(context),
      onModelReady: (value) => value.initView(),
      builder: (context, viewModel, child) {
        return Scaffold(
          body: Stack(
            children: <Widget>[
              Positioned(
                top: 0,
                bottom: viewModel.getIndex == 1 ? ScreenUtil().setWidth(115) : 0,
                left: 0,
                right: 0,
                child: SingleChildScrollView(
                  child: Column(
                    children: <Widget>[
                      Image.network(
                        Constant.nullImage,
                        height: ScreenUtil().setWidth(798),
                        width: double.maxFinite,
                        fit: BoxFit.cover,
                      ),
                      Padding(
                        padding: EdgeInsets.only(
                            left: ScreenUtil().setWidth(35),
                            right: ScreenUtil().setWidth(35),
                            bottom: ScreenUtil().setWidth(35),
                            top: ScreenUtil().setWidth(51)),
                        child: Row(
                          children: <Widget>[
                            Expanded(
                              child: Text(
                                "新学期，新起点。开学第一课",
                                style: TextStyles.textDarkBold43,
                              ),
                            ),
                            Container(
                              padding:
                                  EdgeInsets.only(left: 10, top: 3, bottom: 3),
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                color: Colors.black12,
                                borderRadius: BorderRadius.circular(50),
                              ),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  Icon(Icons.grade,
                                      color: Colors.blue,
                                      size: ScreenUtil().setWidth(35)),
                                  Padding(
                                    padding: EdgeInsets.only(
                                        left: 3,
                                        right: ScreenUtil().setWidth(35)),
                                    child: Text("已收藏",
                                        style: TextStyles.textContent31),
                                  ),
                                ],
                              ),
                            )
                          ],
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        padding: EdgeInsets.only(
                          left: ScreenUtil().setWidth(35),
                          right: ScreenUtil().setWidth(35),
                        ),
                        child: Text(
                          "简介：本课程为中国学生量身定制，从英汉语音对比的角度出发，带领同学们了解、感受、实践英语之“声”——英语的音和韵，体会“听音辨意，意通音达”的语音学习真谛。",
                          style: TextStyles.textContent31,
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        padding: EdgeInsets.only(
                          top: ScreenUtil().setWidth(50),
                          left: ScreenUtil().setWidth(35),
                          right: ScreenUtil().setWidth(35),
                          bottom: ScreenUtil().setWidth(35),
                        ),
                        child: Text(
                          "高一·语文",
                          textAlign: TextAlign.start,
                          style: TextStyles.textGray37,
                        ),
                      ),
                      Container(height: 10, color: Colors.black12),
                      Container(
                        height: 45,
                        color: Colors.white,
                        child: NoticeTabWidget(
                          //隐藏
                          rightUnread: false,
                          //是否显示
                          openScreen: true,
                          listTab: viewModel.listTab,
                          getIndex: (index) => viewModel.tapModelOnTap(index),
                        ),
                      ),
                      IndexedStackWidget(),
                    ],
                  ),
                ),
              ),
              //底部按钮
              Positioned(
                bottom: 0,
                left: 0,
                right: 0,
                child: Visibility(
                  visible: viewModel.getIndex == 1,
                  child: ButtonWidget().rectangleButtonWidget(
                      buttonName: "购买课程",
                      onPressed: () {
                        Application().navigatePushToPage(
                            context, Routes.confirmCorderPage, {});
                      }),
                ),
              ),
              //返回按钮
              Positioned(
                top: 0,
                left: 0,
                child: GestureDetector(
                  child: Container(
                    width: ScreenUtil().setWidth(60),
                    height: ScreenUtil().setWidth(60),
                    margin: EdgeInsets.only(
                      top: ScreenUtil().setWidth(19) +
                          ScreenUtil.statusBarHeight,
                      left: ScreenUtil().setWidth(30),
                    ),
                    alignment: Alignment.center,
                    padding: EdgeInsets.only(right: 2),
                    decoration: BoxDecoration(
                        color: Colors.black38,
                        borderRadius: BorderRadius.circular(50)),
                    child: Icon(
                      Icons.arrow_back_ios,
                      size: ScreenUtil().setSp(40),
                      color: Colors.white,
                    ),
                  ),
                  onTap: () => Navigator.pop(context),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}

class IndexedStackWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    CoureDetailsViewModel coureDetailsViewModel = Provider.of(context);

    switch (coureDetailsViewModel.getIndex) {
      case 0:
        return Container(
          padding: EdgeInsets.all(5),
          child: Column(
            children: <Widget>[
              Padding(
                padding: EdgeInsets.only(bottom: 5),
                child: Image.network(
                  Constant.nullImage,
                  height: ScreenUtil().setWidth(798),
                  width: double.maxFinite,
                  fit: BoxFit.cover,
                ),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 5),
                child: Image.network(
                  Constant.nullImage,
                  height: ScreenUtil().setWidth(798),
                  width: double.maxFinite,
                  fit: BoxFit.cover,
                ),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 5),
                child: Image.network(
                  Constant.nullImage,
                  height: ScreenUtil().setWidth(798),
                  width: double.maxFinite,
                  fit: BoxFit.cover,
                ),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 5),
                child: Image.network(
                  Constant.nullImage,
                  height: ScreenUtil().setWidth(798),
                  width: double.maxFinite,
                  fit: BoxFit.cover,
                ),
              ),
              Container(
                alignment: Alignment.center,
                child: Text("-END-"),
              )
            ],
          ),
        );
      case 1:
        return Container(
          padding: EdgeInsets.all(5),
          child: ListView.builder(
              physics: NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              itemCount: 10,
              itemBuilder: (context, index) {
                return ListTile(
                  title: Text("第1课：找对方法，才有资格说速成"),
                  subtitle: Text("2020-06-12 20:20"),
                );
              }),
        );
      default:
      return Container();
    }
  }
}
